<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*"%>
<%@page import="support.*"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Choose Location Page</title>
</head>
<body>
	<p>
		Hello,
		<%=session.getAttribute("FirstName")%>
		<%=session.getAttribute("MiddleI")%>
		<%=session.getAttribute("LastName")%>
		<%
			String action = request.getParameter("action");
		%>

		<%
			//3 possible pages link to degreelocation.jsp
			//from address.jsp , means country of residency is US
			if (action.equals("addr")) {

				String StreetAddress = request.getParameter("StreetAddress");
				session.setAttribute("StreetAddress", StreetAddress);

				String City = request.getParameter("City");
				session.setAttribute("City", City);

				String AddressState = request.getParameter("AddressState");
				session.setAttribute("AddressState", AddressState);

				String ZipCode = request.getParameter("ZipCode");
				session.setAttribute("ZipCode", ZipCode);

				String AreaCode = request.getParameter("AreaCode");
				session.setAttribute("AreaCode", AreaCode);

				session.setAttribute("USResident", "US Permanent Resident");

				Vector<university> uni = new Vector<university>();
				session.setAttribute("uni", uni);

			} else if (request.getParameter("action").equals("resd")) { //country of residency is not US
				String USResident = request.getParameter("USResident");
				if (USResident.equals("T")) {
					session.setAttribute("USResident", "US Permanent Resident");
				}
				if (USResident.equals("F")) {
					session.setAttribute("USResident", "Non-Resident");
				}

				Vector<university> uni = new Vector<university>();
				session.setAttribute("uni", uni);
			} else if (request.getParameter("action").equals("demore")) { //loop of degree, add more locations
				university u = new university();
				u.setLocation(session.getAttribute("location").toString());
				u.setUniversity(session.getAttribute("university").toString());
				u.setMonth(session.getAttribute("month").toString());
				u.setYear(session.getAttribute("year").toString());
				u.setDegreeDiscipline(session.getAttribute("degreeDiscipline")
						.toString());
				u.setGPA(session.getAttribute("GPA").toString());
				u.setTitle(session.getAttribute("Title").toString());
				//u.setOther(session.getAttribute("Other").toString());

				Vector<university> uni = (Vector<university>) session
						.getAttribute("uni");
				uni.add(u);
				session.setAttribute("uni", uni);
			}
		%>
	
	<p>
		Please choose your location:
		<%
			support s = new support();

			//getUniversities returns a vector of vectors where each vector is a tuple of <string, vector>
			//with the string being the name of the country/state and the vector being the list of universities there
			Vector stateVec = s.getStateofUniversities();

			//print all the universities by state/country
		%>
	
	<form method="get" action="degreeUniversity.jsp">
		<table border="1">
			<%
				//display all states that have known universities
				for (int i = 0; i < stateVec.size() / 3; i++) {
					String state = (String) stateVec.get(i * 3);
			%>
			<tr>
				<td><a href="degreeUniversity.jsp?stateName=<%=state%>"> <%
 	out.println("<br>" + state + "<br>");
 %> <%
 	String state2 = (String) stateVec.get(i * 3 + 1);
 %>
				</a></td>
				<td><a href="degreeUniversity.jsp?stateName=<%=state2%>"> <%
 	out.println("<br>" + state2 + "<br>");
 %> <%
 	String state3 = (String) stateVec.get(i * 3 + 2);
 %>
				</a></td>
				<td><a href="degreeUniversity.jsp?stateName=<%=state3%>"> <%
 	out.println("<br>" + state3 + "<br>");
 	}
 %>
				</a></td>
			</tr>
			<%
				//print the last row of states
				if (stateVec.size() % 3 != 0) {
					for (int i = 0; i < stateVec.size() % 3; i++) {
						String state4 = (String) stateVec.get(stateVec.size() - 1
								- i);
			%>
			<tr>
				<td><a href="degreeUniversity.jsp?stateName=<%=state4%>"> <%
 	out.println(state4);
 %>
				</a></td>
			</tr>
			<%
				}
				}
			%>
		</table>
	</form>
</body>
</html>